/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021.
 * Description: support nohz_enhance feature
 * Author: huwanming <huwanming@huawei.com>
 * Create: 2021-07-17
 */

#include <linux/sched/isolation.h>
#include <linux/rtos_nohz_enhance.h>

bool forcing_vtimer;
bool nohz_enhance_enabled;

void bind_kthread_hk_cpu(struct task_struct *tsk, const struct cpumask *old_cpumask)
{
	struct cpumask cpumask_non_nohz;

	if (!cpumask_empty(old_cpumask)) {
		cpumask_and(&cpumask_non_nohz, old_cpumask, housekeeping_cpumask(HK_FLAG_KTHREAD));
		if (!cpumask_empty(&cpumask_non_nohz))
			set_cpus_allowed_ptr(tsk, &cpumask_non_nohz);
		else
			set_cpus_allowed_ptr(tsk, old_cpumask);
	}
}

#ifdef CONFIG_ARM_ARCH_TIMER
static int __init force_vtimer_setup(char *str)
{
	forcing_vtimer = true;
	pr_info("nohz_enhance: use vtimer as arch_timer\n");

	return 0;
}
__setup("force_vtimer", force_vtimer_setup);
#endif

static int __init nohz_enhance_setup(char *str)
{
	nohz_enhance_enabled = true;
	pr_info("nohz_enhance: enabled nohz enhancement\n");

	return 0;
}
__setup("nohz_enhance", nohz_enhance_setup);
